﻿using System;
using System.Collections;
using CardLogistics.Model.CardRecovery;
using System.Data;
using System.Data.OracleClient;


namespace CardLogistics.DAL.CardRecovery
{
    public class CARDRECOVERY_SCRAPData
    {
        #region 新增或编辑操作
        /// <summary>
        /// 执行新增或编辑操作
        /// </summary>
        /// <param name="listSQL"></param>
        /// <returns></returns>
        public int AddOrEdit(ArrayList listSQL)
        {
            return DbHelperSQL.ExecuteSqlTran(listSQL);
        }
        #endregion


        #region 查询
        /// <summary>
        /// 根据条件查询相应的表的字段
        /// </summary>
        /// <param name="StrWhere">查询条件</param>
        /// <param name="StrFields">要查询的字段</param>
        /// <returns>填充完数据的DataTable</returns>
        public DataTable GetList(string StrWhere, string StrFields)
        {
            return CommonData.GetListOrderBy(StrWhere, "V_CARDRECOVERY_SCRAP", StrFields, "ID", 0);
        }

        /// <summary>
        /// 根据编号查询基本信息
        /// </summary>
        /// <param name="id">编号</param>
        /// <returns>填充完数据的DataTable</returns>
        public DataTable GetInfoById(string id)
        {
            return GetList(" ID = '" + id + "' ", "*");
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public CARDRECOVERY_SCRAP GetModel(string id)
        {
            DataRow row = GetInfoById(id).Rows[0];
            CARDRECOVERY_SCRAP model = new CARDRECOVERY_SCRAP();
            if (row != null)
            {
                if (row["ID"] != null)
                {
                    model.ID = row["ID"].ToString();
                }
                if (row["SCRAPNO"] != null)
                {
                    model.SCRAPNO = row["SCRAPNO"].ToString();
                }
                if (row["SCRAPDATA"] != null && row["SCRAPDATA"].ToString() != "")
                {
                    model.SCRAPDATA = DateTime.Parse(row["SCRAPDATA"].ToString());
                }
                if (row["REMARKS"] != null)
                {
                    model.REMARKS = row["REMARKS"].ToString();
                }
                if (row["LASTUPDATEUSER"] != null)
                {
                    model.LASTUPDATEUSER = row["LASTUPDATEUSER"].ToString();
                }
                if (row["LASTUPDATEDATE"] != null && row["LASTUPDATEDATE"].ToString() != "")
                {
                    model.LASTUPDATEDATE = DateTime.Parse(row["LASTUPDATEDATE"].ToString());
                }
                if (row["ISSUBMIT"] != null && row["ISSUBMIT"].ToString() != "")
                {
                    model.ISSUBMIT = decimal.Parse(row["ISSUBMIT"].ToString());
                }
            }
            return model;
        }
        #endregion

        #region 删除
        /// <summary>
        /// 删除信息
        /// </summary>
        /// <param name="id">删除信息的ID</param>
        /// <returns>删除成功返回True。否则返回false</returns>
        public string Delete(string id)
        {
            try
            {
                OracleParameter[] parameters = {
                        new OracleParameter("varOut",  OracleType.VarChar,100),
					    new OracleParameter("vid",  OracleType.VarChar,50)
                };
                parameters[0].Direction = ParameterDirection.Output;
                parameters[1].Value = id;
                string strOutPar = DbHelperSQL.RunProcedure("p_cardrecovery_scrap_delete", parameters, parameters[0]).ToString();
                return strOutPar;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
    }
}
